home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / SDKs / Word Services SDK 1.0.6 / Writeswell Jr 1.2.1 Sources ƒ / Writeswell Jr. Source / RegMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-11  |  4.6 KB  |  263 lines  |  [TEXT/KAHL]

  1. /* RegMenu.c
  2.  * Handle the Registration menu in Writeswell Jr.
  3.  * Copyright ©1993 Working Software, Inc.  All Rights Reserved.
  4.  * 8 Mar 93 Mike Crawford
  5.  */
  6.  
  7. #include "TBConstants.h"
  8. #include "TBGlobals.h"
  9. #include "RegMenu.h"
  10. #include "WWJrAbout.h"
  11. #include "OutlineButton.h"
  12. #include "PrintWWJr.h"
  13. #include "MyFiles.h"
  14. #include "MyTextEdit.h"
  15.  
  16. void InstallVersionText( DialogPtr dlg, short item );
  17. void PrintRegCard( StringPtr addrStr );
  18. void SaveRegCard( StringPtr addrStr );
  19. OSErr CreateRegWindow( StringPtr addrStr );
  20. void GetVersionString( StringPtr versStr );
  21.  
  22. Boolean DoRegMenu( short theItem )
  23. {
  24.     switch( theItem ){
  25.         case kRMAboutMe:
  26.             DoAboutMe();
  27.             break;
  28.         case kRMRegister:
  29.             RegisterForm();
  30.             break;
  31.         default:
  32.             break;
  33.     }
  34.  
  35.     return true;
  36. }
  37.  
  38. void RegisterForm( void )
  39. {
  40.     DialogPtr    dlg;
  41.     short        item;
  42.     short        curFile;
  43.     Handle        h;
  44.     short        kind;
  45.     Rect        r;
  46.     Boolean        dialogDone;
  47.     Str255        addrStr;
  48.     
  49.     dlg = GetNewDialog( kRegDlgID, (Ptr)NULL, (WindowPtr) -1 );
  50.  
  51.     if ( !dlg )
  52.         return;
  53.     
  54.     curFile = CurResFile();
  55.     UseResFile( gAppFileRefNum );
  56.  
  57.     /* 1.1 display the version number from the 'vers' resource -
  58.      */
  59.  
  60.     InstallVersionText( dlg, kRDVersionStringItem );
  61.     SelIText( dlg, kRDTextEntryItem, 0, 32767 );
  62.     
  63.     dialogDone = false;
  64.  
  65.     do {
  66.         ModalDialog( (ModalFilterUPP)NULL, &item );
  67.         
  68.         switch ( item ){
  69.             case kRDPrintButton:
  70.             case kRDSaveButton:
  71.             case kRDDoneButton:
  72.                 dialogDone = true;
  73.                 break;
  74.             default:
  75.                 break;
  76.         }
  77.     } while ( !dialogDone );
  78.  
  79.     if ( item != kRDDoneButton ){
  80.         GetDItem( dlg, kRDTextEntryItem, &kind, &h, &r );
  81.         GetIText( h, addrStr );
  82.     }
  83.  
  84.     DisposDialog( dlg );
  85.     
  86.     UseResFile( curFile );
  87.  
  88.     switch ( item ){
  89.         case kRDPrintButton:
  90.             PrintRegCard( addrStr );
  91.             break;
  92.         case kRDSaveButton:
  93.             SaveRegCard( addrStr );
  94.             break;
  95.         default:
  96.             break;
  97.     }
  98.  
  99.     return;
  100. }
  101.  
  102. void InstallVersionText( DialogPtr dlg, short item )
  103. {
  104.     short        kind;
  105.     Handle        h;
  106.     Rect        r;
  107.     Str255        versStr;
  108.     
  109.     GetVersionString( versStr );
  110.  
  111.     GetDItem( dlg, item, &kind, &h, &r );
  112.  
  113.     SetIText( h, versStr );
  114.     
  115.  
  116.     return;
  117. }
  118.  
  119. void GetVersionString( StringPtr versStr )
  120. {
  121.     StringPtr    shortVersion;
  122.     VersRecHndl    versH;
  123.  
  124.     versH = (VersRecHndl)Get1Resource( 'vers', rVersID );
  125.  
  126.     if ( !versH ){
  127.         versStr[ 0 ] = '\0';
  128.         return;
  129.     }
  130.  
  131.     shortVersion = (*versH)->shortVersion;
  132.     
  133.     BlockMove( shortVersion, versStr, shortVersion[ 0 ] + 1 );
  134.  
  135.     return;
  136. }
  137.  
  138. void PrintRegCard( StringPtr addrStr )
  139. {
  140.     WindowPtr        oldDocWindow;
  141.     Boolean            oldDocDirty;
  142.     Boolean            oldDocExists;
  143.     ControlHandle    oldVertScroll;
  144.     short            oldLinesPerPage;
  145.  
  146.     /* STUB handle this by supporting multiple open windows */
  147.     
  148.     oldDocWindow = gDocWindow;
  149.     oldDocDirty = gDocDirty;
  150.     oldDocExists = gDocExists;
  151.     oldVertScroll = gVertScroll;
  152.     oldLinesPerPage = gLinesPerPage;
  153.     
  154.     if ( oldDocWindow )
  155.         HideWindow( oldDocWindow );
  156.     
  157.     gDocWindow = (WindowPtr)NULL;
  158.  
  159.     if ( !CreateRegWindow( addrStr ) ){
  160.     
  161.         DoPrint();
  162.         
  163.     }
  164.  
  165.     if ( gDocWindow )
  166.         DisposeWindow( gDocWindow );
  167.  
  168.     gDocWindow = oldDocWindow;
  169.     gDocDirty = oldDocDirty;
  170.     gDocExists = oldDocExists;
  171.     gVertScroll = oldVertScroll;
  172.     gLinesPerPage = oldLinesPerPage;
  173.     
  174.     if ( gDocWindow )
  175.         ShowWindow( gDocWindow );
  176.     
  177.     return;
  178. }
  179.  
  180. void SaveRegCard( StringPtr addrStr )
  181. {
  182.     WindowPtr        oldDocWindow;
  183.     Boolean            oldDocDirty;
  184.     Boolean            oldDocExists;
  185.     ControlHandle    oldVertScroll;
  186.     short            oldLinesPerPage;
  187.  
  188.     /* STUB handle this by supporting multiple open windows */
  189.     
  190.     oldDocWindow = gDocWindow;
  191.     oldDocDirty = gDocDirty;
  192.     oldDocExists = gDocExists;
  193.     oldVertScroll = gVertScroll;
  194.     oldLinesPerPage = gLinesPerPage;
  195.     
  196.     if ( oldDocWindow )
  197.         HideWindow( oldDocWindow );
  198.     
  199.     gDocWindow = (WindowPtr)NULL;
  200.  
  201.     if ( !CreateRegWindow( addrStr ) ){
  202.     
  203.         DoSave();
  204.         DoCloseWindow();
  205.         
  206.     }
  207.  
  208.     if ( gDocWindow )
  209.         DisposeWindow( gDocWindow );
  210.  
  211.     gDocWindow = oldDocWindow;
  212.     gDocDirty = oldDocDirty;
  213.     gDocExists = oldDocExists;
  214.     gVertScroll = oldVertScroll;
  215.     gLinesPerPage = oldLinesPerPage;
  216.     
  217.     if ( gDocWindow )
  218.         ShowWindow( gDocWindow );
  219.     
  220.     return;
  221. }
  222.  
  223. OSErr CreateRegWindow( StringPtr addrStr )
  224. {
  225.     OSErr        err;
  226.     TEHandle    textH;
  227.     Handle        headTextHdl;
  228.     long        headSize;
  229.     short        curFile;
  230.     Str255        versStr;
  231.     
  232.     if ( err = MakeNewWindow() )
  233.         return err;
  234.     
  235.     textH = GetTextHandle( gDocWindow );
  236.  
  237.     curFile = CurResFile();
  238.     UseResFile( gAppFileRefNum );
  239.     
  240.     headTextHdl = Get1Resource( 'TEXT', kHeadTextID );
  241.     
  242.     if ( !headTextHdl )
  243.         return resNotFound;
  244.     
  245.     headSize = GetHandleSize( headTextHdl );
  246.     
  247.     HLock( headTextHdl );
  248.  
  249.     TEInsert( *headTextHdl, headSize, textH );
  250.     
  251.     HUnlock( headTextHdl );
  252.     ReleaseResource( headTextHdl );
  253.  
  254.     GetVersionString( versStr );
  255.     TEInsert( &versStr[ 1 ], (long)versStr[ 0 ], textH );
  256.  
  257.     TEInsert( "\015", 1, textH );
  258.  
  259.     TEInsert( &addrStr[ 1 ], (long)addrStr[ 0 ], textH );
  260.     
  261.     return noErr;
  262. }
  263.